# 练习  素数

# def is_prime(n):
#     if n <=1:
#         return False
#     for i in range(2, n):
#         if n % i == 0:
#             return False
#     return True

# print(is_prime(5))

# 练习2 ============ 实现range

# def myrange(*args):
#     if len(args)<=0 or len(args)>3:
#         raise TypeError('参数错误')
#     if len(args) == 1:
#         start = 0
#         stop = args[0]
#         step = 1
#     elif len(args) == 2:
#         start = args[0]
#         stop = args[1]
#         step = 1
#     elif len(args) == 3:
#         start = args[0]
#         stop = args[1]
#         step = args[2]
#     result = []
#     cur_numner = start
#     if step >0:
#         while cur_numner <stop:
#             result.append(cur_numner)
#             cur_numner +=step
#     elif step < 0:
#         while cur_numner > stop:
#             result.append(cur_numner)
#             cur_numner += step
#     return result
#
# l1 = myrange(10,1,-2)
# print(l1)

# 新语句    yield   生成器函数=====================
# def myrange2():
#     yield xxx
#
# generator = (s ** 2 for s in range(1,5))
# it = iter(generator)
# print(next(it))
# print(next(it))
# print(next(it))
# print(next(it))
# scores = [100,60,50,30,20,99,88]
# def myfilter(scores):
#     pass_scores =(s for s in scores if s >= 60)
#
#     return pass_scores
#
#
# pass_scores = list(myfilter(scores))
#
# print(pass_scores)
# names = ['中国移动','中国联通','中国电信']

# numbers =['10086','10010','10000']
## 练习用函数 zip  遍历两个可迭代对象

# for t in zip(names,numbers):
#     print(t)
#     print(t[0],'的客服电话是：',t[1])
# for i in enumerate(names,start=0):
#     print(i)
#     number,name = i
#     print(f'{number},{name}')

# 练习用函数  写一个和 enumerate 功能一样的函数  枚举  可迭代对象加上自定义序号

# def myenumerate(x,start=0):
#     it = iter(x)
#     while True:
#         try:
#             value=next(it)
#             yield start,value
#             start += 1
#         except StopIteration:
#             break
# for t in myenumerate('abc'):
#     print(t)

# 高阶函数==========map （用函数，来处理可迭代对象）， filter筛选， sorted 排序
# l1 = [1,2,3,4]
# l2 = [5,6,7,8,9]
# def mypower(x,y):
#     return x**y
# for result in map(mypower,l2,l1):
#     print(result)

# scores = [100,58,60,20,40,88]
#
# def jige(scores):
#     return scores >=60
# jige_scores = list(filter(jige,scores))
# print(jige_scores)

# class Student:
#     def __init__(self, name, sex, age, scores):
#         self.name = name
#         self.sex  = sex
#         self.age = age
#         self.scores = scores
#     def nan(self):
#         return self.sex =='男'
#     def nv(self):
#         return self.sex =='女'
#     def jige(self):
#         return self.scores >= 60
#     def __repr__(self):
#         return f"Student('{self.name}','{self.sex}',{self.age},{self.scores})"
#
#
# class_1 = [Student('小张', '男', 18, 79),
#            Student('小余', '女', 18, 59),
#            Student('小行', '男', 18, 29),
#            Student('小李', '女', 18, 99)
#            ]
#
# # male_list = list(filter(Student.nan,class_1))
# # female_list = list(filter(Student.nv,class_1))
# # jige_list = list(filter(Student.jige,class_1))
# # print('男生：',male_list)
# # print('男生：',female_list)
# # print('及格的有：',jige_list)
# # # 男放到  列表 male_list
# # # 女放到  列表 female_list
# # # 所有及格的    放到 jige_list\
# # def getkey(s):
# #     return s.scores
# l1 = sorted(class_1, key = lambda s: s.scores ,reverse=True)
# print(l1)

